Using Observable
data = transpose(dataT)
function lr(pw){
return(
Plot.plot({
marks: [
Plot.dot(data, {x: "x", y: "y"}),
Plot.line(curve(data), {x: "x", y: "y"})
],
y: {
label: "Blutdruck",
domain: [80,200]
},
x: {
label: "Alter",
domain: [15,80]
},
width: pw,
height: pw/1.5,
color: "steelblue"
})
)
}
function curve(template){
const ages = template.map(d => d.x);
const [minAge, maxAge] = d3.extent(ages);
const xvals = d3.range(minAge, maxAge, (maxAge - minAge) / 100);
let yhat = xvals.map(x => w*x + b);
return xvals.map((x, i) => ({x, y: yhat[i]})); //Thanks ChatGPT
}
lr(900)function color(value) {
return d3.scaleLinear().domain([-1, 0, 1]).range(['blue', 'gray', 'green'])(value);
}
function lw(value) {
return d3.scaleLinear().domain([-1, 1]).range([0.1, 1])(value);
}
dot`${my_graph}`my_graph = `digraph {
node [fontsize=20, fontname=Arial];
node [fixedsize=true, width=0.6, height=0.6];
edge [arrowhead=vee, arrowsize=0.7];
//b -> Y[penwidth=${10*lw(Math.abs(b))}, label=${b}]; //<-- Change the factor here
b -> Y[penwidth=2, label=${b}];
x1 -> Y[penwidth=2, label=${w}];
x1 [label="x", pos="0,0"];
b [label="1", pos="0,2"];
Y [label="y", pos="1,0.8"];
}`